/**
 * Created by yc on 2017/5/24.
 */
import React from 'react'
import {Table} from 'antd';
import PropTypes from 'prop-types';

import ListRowTools from './ListRowTools';
// table的表头
const columns = [
    {
        title: '名称',
        dataIndex: 'name',
        key: 'name',
        width: '60%',
    }, {
        title: '类型',
        dataIndex: 'type',
        key: 'type',
        width: '20%',
    }, {
        title: '操作',
        dataIndex: 'operation',
        key: 'operation',
        render: (data, row) => {//这里data是undefined, index代表这一行的json数据
            const propListRowTools = {
                row
            }
            return (
                <ListRowTools {...propListRowTools} />
            )
        }
    }
];

// table内row的选择事件
const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
        console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
    },
    onSelect: (record, selected, selectedRows) => {
        console.log(record, selected, selectedRows);
    },
    onSelectAll: (selected, selectedRows, changeRows) => {
        console.log(selected, selectedRows, changeRows);
    },
};

// 组件本身
const List = ({dataSource}) => {

    return (
        <Table
            columns={columns}
            rowSelection={rowSelection}
            dataSource={dataSource}
        />
    );
}

// 组件prop默认值
List.defaultProps = {
    dataSource: []
};
// 组件prop验证
List.propTypes = {
    dataSource: PropTypes.array.isRequired
}

export default List;